const mutations = {
    SAVE(state, user) {
        if (user) {
            state.user = user;
        }
        localStorage.state = JSON.stringify(state);
    },
    READ(state) {
        if (localStorage.state) {
            var localState = JSON.parse(localStorage.state);
            state.user = localState.user || '';
            state.selectedMenu = localState.selectedMenu || '';
        }
    },
    
    CHECK_LOGIN(state) {
        if (state.user.username.length > 0 && state.user.password.length > 0) {
            return true;
        } else {
            return false;
        }
    },
    LOG_OUT(state) {
        state.user.username = '';
        state.user.password = '';
    },
    UPDATE_SELECTE_MENU(state, p) {
        state.selectedMenu = parseInt(p);
    }
};


export default mutations